//import fs from 'fs'
const https = require('https');
const fs = require('fs');
const path = require('path');
const cheerio = require('cheerio')

let url = 'https://ncov.dxy.cn/ncovh5/view/pneumonia?from=timeline&isappinstalled=0';

https.get(url, function (res) {
  let chunks=[],size=0;
  res.on('data', function (chunk) {
    //console.log(chunk);
    chunks.push(chunk);
    size+=chunk.length;
  });

  res.on('end', function () {
    console.log('数据包传输完毕');
    let data = Buffer.concat(chunks, size);
    //console.log(data);
    let htmls = data.toString();
    //console.log(html);
    //let result=[];
    let window = {}
    const $ = cheerio.load(htmls)
    const html = $('#getAreaStat').html()
    eval(html) //用js方法执行字符串
    fs.writeFile(path.resolve(__dirname, 'index1.json'), JSON.stringify(window.getAreaStat), () => {
      console.log('保存成功');

    })
  });
})